package com.xx.text;

import com.xx.dao.auctionuser.UserDao;
import com.xx.entity.AuctionUser;
import com.xx.entity.VO.AuctionUserVo;
import com.xx.service.AuctionService;
import com.xx.service.Impl.AuctionServiceImpl;
import com.xx.service.Impl.UserServiceImpl;
import com.xx.service.UserService;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author 许欣
 * 时间：2022/4/12 10:45
 * 描述：
 */
public class User {


    public static void main(String[] args) throws IOException {
        //userName,userPassword,userCardNo,userTel,userAddress,userPostNumber
        //添加
//        AuctionUserVo user=new AuctionUserVo("里斯1","123456","430235486215987463","185059635478","郴州","8655");
//        user.setUserName("里斯");
//        user.setUserPassword("123456");
//        user.setUserCardNo("430235486215987463");
//        user.setUserTel("185059635478");
//        user.setUserAddress("郴州");
//        user.setUserPostNumber("8655");
//        String resource = "mybatis-config.xml";
//        InputStream is = Resources.getResourceAsStream(resource);
//        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
//        SqlSession sqlSession = sqlSessionFactory.openSession();
//        //UserDao userDao=sqlSession.getMapper(UserDao.class);
//        UserService dao=new UserServiceImpl();
//        int ret=dao.add(user);
//        sqlSession.commit();
//        sqlSession.rollback();
//        sqlSession.close();
//        if(ret>0){
//            System.out.println("添加成功");
//        }else {
//            System.out.println("添加失败");
//        }
//
//        //查询用户名，密码
        String resource = "mybatis-config.xml";
        InputStream is = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        //UserDao userDao=sqlSession.getMapper(UserDao.class);
        UserService userDao=new UserServiceImpl();
        AuctionUser user=userDao.getUser("lisi");
        sqlSession.close();
        System.out.println(user.getUserPassword());
    }
}
